﻿using System;
using System.Configuration;
using System.Web;

namespace Shuba.Web.parameter
{
    public partial class parameter_approval : basePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string acl = GetUserAccess("MSTR_PARAM");

                if (!IsUserChecker(acl))
                {
                    string msg = this.GetGlobalResourceObject("Messages", "NoPrivilege").ToString();
                    AlertAndRedirect(msg, ResolveUrl(ConfigurationManager.AppSettings["default_url"]));
                }

                LabelTitle.Text = GetPageTitle("MSTR_PARAM");

                hidID.Value = Request.QueryString["id"];

                Shuba.Business.AppParam bl = new Shuba.Business.AppParam();
                Shuba.Model.AppParamInfo bi;

                bi = bl.GetApprovalByID(Convert.ToByte(hidID.Value));
                lblGuFUP.Text = bi.GU_FUP.ToString();
                lblGuCDFunding.Text = bi.GU_CLOSE_DEAL_FUNDING.ToString();
                lblGuFUPFunding.Text = bi.GU_FUP_FUNDING.ToString();
                lblGuCD.Text = bi.GU_CLOSE_DEAL.ToString();
                lblPurging.Text = bi.PURGING_PERIOD.ToString();
                lblPurgWeb.Text = bi.PURGING_PERIOD_WEB.ToString();
                dtProcessDate.Text = bi.PROCESS_DATE.ToString("dd MMMM yyyy");
                lblNPWP.Text = bi.NPWP.ToString();
                lblTimeOut.Text = bi.TIME_OUT.ToString();
                lblRefresh.Text = bi.REFRESH_TIME.ToString();
                lblProcessingDate.Text = bi.IS_AUTO_PROCESS_DATE == "1" ? "Auto" : "Manual";
                lblJobFinalDedup.Text = bi.JOB_FINAL_DEDUP.ToString();
                lblFinalDedup.Text = bi.IS_NEED_FINAL_DEDUP == "1" ? "Yes" : "No";
            }
        }

        protected void btnApprove_Click(object sender, EventArgs e)
        {
            string msg = "";
            string IsApprove = ddlApprove.SelectedItem.Value;
            string id = hidID.Value;

            Shuba.Business.AppParam bl = new Shuba.Business.AppParam();
            Shuba.Model.AppParamInfo bi = new Shuba.Model.AppParamInfo();

            bi = bl.GetApprovalByID(Convert.ToByte(id));
            bi.UPDATE_BY = HttpContext.Current.User.Identity.Name;
            bi.UPDATE_DATE = ProcessingDate();

            if (IsApprove == "1")
            {
                bl.Approve(Convert.ToByte(id), ConfigurationManager.AppSettings["db.name"], Convert.ToInt32(bi.JOB_FINAL_DEDUP));
                AddLog("APPROVAL", "APPROVE APP PARAM");
                msg = this.GetGlobalResourceObject("Messages", "ApproveAlert").ToString();
            }
            else
            {
                bl.Reject(Convert.ToByte(id));
                AddLog("APPROVAL", "REJECT APP PARAM");
                msg = this.GetGlobalResourceObject("Messages", "NoApprove").ToString();
            }

            AlertAndRedirect(msg, "parameter_list.aspx");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("parameter_list.aspx");
        }
    }
}